package com.jiang.myfm.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.jiang.myfm.R;
import com.jiang.myfm.fragment.BillboardInfoFragment;
import com.jiang.myfm.fragment.BillboardInfoMenuFragment;

public class BillboardInfoActivity extends AppCompatActivity implements View.OnClickListener{

    private Toolbar toolbar;
    private ActionBar actionBar;
    private TextView titleTextView;
    private BillboardInfoFragment billboardInfoFragment;
    private BillboardInfoMenuFragment billboardInfoMenuFragment;
    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;
    private Button backBtn;
    private Button shareBtn;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_billboard_info);

        init();
    }

    private void init(){

        backBtn = ((Button) findViewById(R.id.back));
        backBtn.setOnClickListener(this);
        shareBtn = ((Button) findViewById(R.id.share));
        shareBtn.setOnClickListener(this);
        toolbar = ((Toolbar) findViewById(R.id.biact_toolbar));
        setSupportActionBar(toolbar);
        actionBar = getSupportActionBar();
        titleTextView = ((TextView) findViewById(R.id.title_tv));

        actionBar.setDisplayShowTitleEnabled(false);
        Bundle bundle = getIntent().getExtras();
        String title = bundle.getString("title");
        titleTextView.setText(title);

        String contentType =  bundle.getString("contentType");
        String key = bundle.getString("key");

        billboardInfoFragment = BillboardInfoFragment.newInstance(contentType,key);
        billboardInfoMenuFragment = BillboardInfoMenuFragment.newInstance(contentType,key);

        fragmentManager = getSupportFragmentManager();
        transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.fragment_container,billboardInfoFragment);
        transaction.add(R.id.fragment_container,billboardInfoMenuFragment);

        if (title.equals("最火节目飙升榜") || title.equals("最多订阅经典榜")){
            transaction.show(billboardInfoMenuFragment);
            transaction.hide(billboardInfoFragment);
        }else {
            transaction.show(billboardInfoFragment);
            transaction.hide(billboardInfoMenuFragment);
        }
        transaction.commit();

    }


        @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                Toast.makeText(this, "返回键被点击了", Toast.LENGTH_SHORT).show();
                finish();
                break;
            case R.id.share:
                Toast.makeText(this, "分享键被点击了", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
